//
//  ViewController.m
//  王宇先_09
//
//  Created by wyx on 16/3/21.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import "ViewController.h"
#import "SecondViewController.h"

@interface ViewController ()<UITextFieldDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.navigationItem.title = @"第一页";
    self.view.backgroundColor = [UIColor redColor];
    //背景图
    UIImageView *logInbackground = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 414, 736)];
    logInbackground.image = [UIImage imageNamed:@"login_bg@2x.jpg"];
    [self.view addSubview:logInbackground];
    [logInbackground release];
    //头像背景
    UIImageView *avatar = [[UIImageView alloc] initWithFrame:CGRectMake((414 - 64) / 2, 143, 64, 64)];
    avatar.image = [UIImage imageNamed:@"login_avatar_default@2x.png"];
    [self.view addSubview:avatar];
    [avatar release];
    //输入框背景
    UIImageView *textfiled = [[UIImageView alloc] initWithFrame:CGRectMake((414 - 301) / 2, 230, 301, 94)];
    textfiled.image = [UIImage imageNamed:@"login_textfield.png"];
    [self.view addSubview:textfiled];
    [textfiled release];
    //登录背景&&Button
    UIButton *denluButton = [UIButton buttonWithType:UIButtonTypeCustom];
    denluButton.frame = CGRectMake((414-290)/2, 370, 290, 44);
    [denluButton setBackgroundImage:[UIImage imageNamed:@"login_btn_blue_nor.png"] forState:UIControlStateNormal];
    [denluButton setBackgroundImage:[UIImage imageNamed:@"login_btn_blue_press.png"] forState:UIControlStateHighlighted];
    [self.view addSubview:denluButton];
    [denluButton addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    //用户名 lable
    UILabel *qqUserLable = [[UILabel alloc] initWithFrame:CGRectMake(65, 235, 100, 40)];
    qqUserLable.text = @"账号：";
    [self.view addSubview:qqUserLable];
    [qqUserLable release];
    //密码 lable
    UILabel *qqKeyLable = [[UILabel alloc] initWithFrame:CGRectMake(65, 280, 100, 40)];
    qqKeyLable.text = @"密码：";
    [self.view addSubview:qqKeyLable];
    [qqKeyLable release];
    //用户名 text
    self.userTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 235, 247, 43)];
    [self.view addSubview:self.userTextField];
    self.userTextField.placeholder = @"请输入账号";
    self.userTextField.clearButtonMode = UITextFieldViewModeAlways;
    [_userTextField release];
    self.userTextField.delegate = self;
    //密码 text
    self.keyTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 280, 247, 43)];
    [self.view addSubview:self.keyTextField];
    self.keyTextField.placeholder = @"请输入密码";
    self.keyTextField.clearButtonMode = UITextFieldViewModeAlways;
    self.keyTextField.secureTextEntry = YES;
    [_keyTextField release];
    self.keyTextField.delegate = self;
    
}
- (void)buttonAction{
    if (![self.userTextField.text isEqualToString:@"893055669"]) {
        //创建提示框
        UIAlertView *alerV = [[UIAlertView alloc] initWithTitle:@"提示信息" message:@"用户名不存在" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
        //显示
        [alerV show];
    }
    else if(![self.keyTextField.text isEqualToString:@"123"]) {
        //创建提示框
        UIAlertView *alerV = [[UIAlertView alloc] initWithTitle:@"提示信息" message:@"密码错误" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
        //显示
        [alerV show];
    }
    self.tabBarController.selectedIndex = 1;
}
//点击空白处回收键盘
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [super touchesEnded:touches withEvent:event];
    [self.view endEditing:YES];
}
//协议点 return 回收
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    //隐藏键盘
    [textField resignFirstResponder];
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
